﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DOAN.Public;

namespace DOAN.DLL
{
    public class KhuyenMaiDAL
    {
        ClsConnection cls;

        public KhuyenMaiDAL()
        {
            cls = new ClsConnection();
        }

        public DataTable Load()
        {
            return cls.GetData("KHUYENMAI_LOAD");
        }

        public int Insert(KhuyenMaiPublic p)
        {
            int Nparameter = 8;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaKhuyenMai";
            name[1] = "@TenKhuyenMai";
            name[2] = "@NgayBatDauKhuyenMai";
            name[3] = "@ThoiHanKhuyenMai";
            name[4] = "@MaDoiTuong";
            name[5] = "@KhuyenMai_Id";
            name[6] = "@NoiDungKhuyenMai";
            name[7] = "@MaGoiCuoc";

            value[0] = p.MaKhuyenMai;
            value[1] = p.TenKhuyenMai;
            value[2] = p.NgayBatDauKhuyenMai;
            value[3] = p.HanApDung;
            value[4] = p.MaDoiTuong;
            value[5] = p.KhuyenMai_Id;
            value[6] = p.NoiDungKhuyenMai;
            value[7] = p.MaGoiCuoc;

            return cls.UpdateData("KHUYENMAI_INSERT", name, value, Nparameter);
        }

        public int Update(KhuyenMaiPublic p)
        {
            int Nparameter = 8;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaKhuyenMai";
            name[1] = "@TenKhuyenMai";
            name[2] = "@NgayBatDauKhuyenMai";
            name[3] = "@ThoiHanKhuyenMai";
            name[4] = "@MaDoiTuong";
            name[5] = "@KhuyenMai_Id";
            name[6] = "@NoiDungKhuyenMai";
            name[7] = "@MaGoiCuoc";

            value[0] = p.MaKhuyenMai;
            value[1] = p.TenKhuyenMai;
            value[2] = p.NgayBatDauKhuyenMai;
            value[3] = p.HanApDung;
            value[4] = p.MaDoiTuong;
            value[5] = p.KhuyenMai_Id;
            value[6] = p.NoiDungKhuyenMai;
            value[7] = p.MaGoiCuoc;

            return cls.UpdateData("KHUYENMAI_UPDATE", name, value, Nparameter);
        }

        public int Delete(KhuyenMaiPublic p)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaKhuyenMai";
            value[0] = p.MaKhuyenMai;
            return cls.UpdateData("KHUYENMAI_DELETE", name, value, Nparameter);
        }

        public DataTable Load_MaGC(GoiCuocPublic p)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaGoiCuoc";
            value[0] = p.MaGoiCuoc;
            return cls.GetData("KHUYENMAI_MAGC", name, value, Nparameter);
        }
    }
}
